package com.zzxx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzxx.mapper.OrdersMapper;
import com.zzxx.pojo.Orders;
import com.zzxx.pojo.Traveller;
import com.zzxx.service.OrdersService;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrdersServiceImpl implements OrdersService {
    @Autowired
    private OrdersMapper ordersMapper;
    @Override
    public Orders findById(String id) {
        return ordersMapper.findById(id);
    }

    @Override
    public void update(Orders orders) {
        ordersMapper.updateProduct(orders.getProduct());
        ordersMapper.updateMember(orders.getMember());
        ordersMapper.updateOrders(orders);
        List<Traveller> list = orders.getTravellers();
        for(int i = 0;i < list.size();i++){
            ordersMapper.updateTravellers(list.get(i));
        }
    }

    @Override
    public PageInfo<Orders> getAllOrders(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Orders> pageInfo = new PageInfo<>(ordersMapper.queryAll());
        return pageInfo;
    }

    @Override
    public void deleteById(String id) {
        ordersMapper.deleteById(id);
    }
}
